package homework.day07;

import java.util.Arrays;

public class PrimeNumber {
    public static void main(String[] args) {
        //--------------1
        showPrimeNumber();
        System.out.println();

        //--------------2
        int[] arr = getPrimeNumber(2,100);
        System.out.println(Arrays.toString(arr));

    }


    public static int[] getPrimeNumber(int start,int end){
        int[] arr = new int[0];
        for(int i=start;i<=end;i++){
            boolean flag = true;
            for(int j=2;j<=i/2;j++){
                if(i%j==0){
                    flag = false;
                    break;
                }
            }
            if(flag){
                arr = Arrays.copyOf(arr,arr.length+1);
                arr[arr.length-1] = i;
            }
        }
        return arr;
    }





    public static void showPrimeNumber(){
        System.out.println("素数是：");
        for(int i=2;i<=100;i++){
            boolean flag = true;
            for(int j=2;j<=i/2;j++){
                if(i%j==0){
                    flag = false;
                    break;
                }
            }
            if(flag){
                System.out.print(i+" ");
            }
        }
    }
}
